﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PaymentHelper.Core.RelatedObject;
using PaymentHelper.Core.ExceptionHandler;
using System.ComponentModel.DataAnnotations;

namespace PaymentHelper.Methods.BaoKim.Models
{
    public class ConfigModel : PaymentHelperModel
    {
        [Required(ErrorMessage = "BusinessEmail is required")]
        public string Email { get; set; }

        [Required(ErrorMessage = "Return Url is required")]
        public string ReturnURL { get; set; }

        [Required(ErrorMessage = "Cancel Url is required")]
        public string CancelURL { get; set; }

        public bool UseSandbox { get; set; }

        [Range(0, 1000, ErrorMessage = "Handling fee must be between 0 and 1000")]
        [Required(ErrorMessage = "Handling fee is required")]
        public decimal HandlingFee { get; set; }

        [Required(ErrorMessage = "Sandbox Url is required")]
        public string SandboxURL { get; set; }

        [Required(ErrorMessage = "NganLuong Url is required")]
        public string BaoKimURL { get; set; }

        public override void InitModel(IList<PHSettingItem> paypalStandardSettings)
        {
            if (paypalStandardSettings == null || paypalStandardSettings.Count == 0)
                throw new PaymentHelperException(ExceptionLevel.Warning, "ConfigModel-InitModel", "List of settings is empty. Loading specified setting failed !");

            Email = GetValueConfig("Email", paypalStandardSettings);
            ReturnURL = GetValueConfig("ReturnURL", paypalStandardSettings);
            CancelURL = GetValueConfig("CancelURL", paypalStandardSettings);
            UseSandbox = GetValueConfig("UseSandbox", paypalStandardSettings);
            HandlingFee = GetValueConfig("HandlingFee", paypalStandardSettings);
            SandboxURL = GetValueConfig("SandboxURL", paypalStandardSettings);
            BaoKimURL = GetValueConfig("BaoKimURL", paypalStandardSettings);
        }

        public override IList<PHSettingItem> ToListAttribute()
        {
            var listAtrr = new List<PHSettingItem>();

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "User Email",
                Name = "Email",
                TypeSetting = Email.GetType(),
                ValueInStr = Email.ToString()
            });

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "Return URL",
                Name = "ReturnURL",
                TypeSetting = ReturnURL.GetType(),
                ValueInStr = ReturnURL.ToString()
            });

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "Cancel URL",
                Name = "CancelURL",
                TypeSetting = CancelURL.GetType(),
                ValueInStr = CancelURL.ToString()
            });

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "Use Sandbox",
                Name = "UseSandbox",
                TypeSetting = UseSandbox.GetType(),
                ValueInStr = UseSandbox.ToString()
            });

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "Handling Fee",
                Name = "HandlingFee",
                TypeSetting = HandlingFee.GetType(),
                ValueInStr = HandlingFee.ToString()
            });

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "Sandbox URL",
                Name = "SandboxURL",
                TypeSetting = SandboxURL.GetType(),
                ValueInStr = SandboxURL.ToString()
            });

            listAtrr.Add(new PHSettingItem()
            {
                DisplayName = "NganLuong URL",
                Name = "BaoKimURL",
                TypeSetting = BaoKimURL.GetType(),
                ValueInStr = BaoKimURL.ToString()
            });

            return listAtrr;
        }
    }
}
